/**
 * Copyright 2023 Inc.
 **/
package com.myz.springclond2021.controller;

import com.myz.springclond2021.config.NacosValueConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author maoyz0621 on 2023/9/15
 * @version v1.0
 */
@RestController
@RequestMapping("/config")
@RefreshScope
public class TestController {

    @Autowired
    private NacosValueConfig nacosValueConfig;

    @Resource(name = "dynamicThreadPoolExecutor")
    private ThreadPoolTaskExecutor threadPoolExecutor;

    @Value(("${thread.corePoolSize:10}"))
    private Integer corePoolSize;

    @Value(("${thread.maxPoolSize:10}"))
    private Integer maxPoolSize;

    @GetMapping(value = "/get")
    public String echo() {
        return "Hello Nacos Config " + "主配置文件：" + nacosValueConfig.getMainVal() + ";\r\n" +
                nacosValueConfig.getVal() + "\r\n,相同配置: " + nacosValueConfig.getCommon() + "\r\n,middle: " + nacosValueConfig.getPort() + " \r\n,mysql:" + nacosValueConfig.getHost();
    }

    @GetMapping(value = "/threadPool")
    public String threadPool() {
        return threadPoolExecutor.getCorePoolSize() + " - " + threadPoolExecutor.getMaxPoolSize() + " - " + corePoolSize + " - " + maxPoolSize;
    }
}